<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020-12-02
  Time: 16:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <base href="<%=request.getContextPath()%>/"/>
  <link rel="stylesheet" href="webjars/layui/2.5.6/css/layui.css">
</head>
<body>
        <div class="layui-main">
            <script type="text/html" id="toolbar">
                <div class="layui-form-item">
                        <label class="layui-form-label">科室:</label>
                        <input type="text" name="departmentName" id="departmentName" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left">
                        <button type="button" class="layui-btn" onclick="search()" style="float: left;margin-left: 20px">查询</button>
                        <button class="layui-btn" lay-event="add" onclick="add()" style="margin-left: 20px">添加</button>
                </div>

            </script>
            <table id="roleTb" lay-filter="roleTb"></table>
            <script type="text/html" id="action">
                <a class="layui-btn layui-btn-xs" lay-event="update">修改</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
        </div>

        <div style="display: none" id="add">
            <form class="layui-form"  action="" lay-filter="add">
                <div class="layui-form-item" style="margin-top: 30px">
                    <input name="dictionaryId" type="hidden"/>
                    <label class="layui-form-label" style="margin-bottom: 20px">科室名称:</label>
                    <input type="text" name="departmentName" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">科室编码:</label>
                    <input type="text" name="departmentCode" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">医院编码:</label>--%>
                    <input type="hidden" value="056001" name="hospitalCode" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">电话:</label>
                    <input type="text" name="phone" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">联系人:</label>
                    <input type="text" name="linkman" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">联系人电话:</label>
                    <input type="text" name="linkmanPhone" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">使用标志:</label>--%>
                    <input type="hidden" name="delFlag" value="y" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">创建者:</label>
                    <input type="text" name="createBy" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                </div>

            </form>
        </div>





            <div id="tree"></div>

<script src="webjars/layui/2.5.6/layui.js"></script>
<script>
        //表格初始化
        layui.use(["table"],function () {
            let table=layui.table;
            table.render({
                id:"roleTb",
                elem:"#roleTb",
                url:"List/search",
                toolbar: "#toolbar",
                page:true,
                cols:[[
                    //{title:"id",field:"departmentId"},
                    {title:"科室名称",field:"departmentName"},
                    {title:"科室编码",field:"departmentCode"},
                    {title:"医院编码",field:"hospitalCode"},
                    {title:"电话",field:"phone"},
                    {title:"联系人",field:"linkman"},
                    {title:"联系人电话",field:"linkmanPhone"},
                    {title:"使用标志",field:"delFlag"},
                    {title: "操作",toolbar:"#action"}
                ]]
            })
            table.on("tool(roleTb)",function ({data,event}){
                switch (event) {
                    case "update":
                        update(data);
                        break;
                    case "del":
                        del(data.departmentId);
                        break;
                }
            });



        })




        function add(){
            layui.use(["layer","jquery","form","table"],function(){
                let $ = layui.$;
                let form = layui.form;
                let layer = layui.layer;
                let table = layui.table;
                $("#add>form")[0].reset();
                layer.open({
                    type:1,
                    offset:'50px',
                    skin:'layui-layer-molv',
                    area:["700px","450px"],
                    content:$("#add"),
                    btn:["确定","取消"],
                    yes(){
                        let params=form.val("add");
                        console.log(params);
                        $.post("List/add",params)
                            .done(({msg})=>{
                                table.reload("roleTb");
                                layer.close(layer.index);
                                layer.msg(msg);
                            });
                    }
                });
            });
        }



        //修改
        function update(data) {
            //console.log(data);
            layui.use(["layer","jquery","form"],function () {
                let layer=layui.layer;
                let $=layui.$;
                layui.form.val("update",data);
                layer.open({
                    type:1,
                    offset:'50px',
                    skin:'layui-layer-molv',
                    area:["500px"],
                    content:$("#update"),
                    btn:["确定","取消"],
                    yes(){
                        let params=layui.form.val("update");
                        $.post("role/update",params)
                        .done(({msg})=>{
                            layer.close(layer.index);
                            layer.msg(msg);
                            layui.table.reload("roleTb");
                        });
                    }
                })
            })
        }





        function del(departmentId){
            layui.use("jquery",function(){
                alert(departmentId);
                let layer=layui.layer;
                layui.$.post('/List/del/',{departmentId:departmentId})
                    .done(({msg})=>{
                        layui.table.reload("roleTb");
                        layer.msg(msg);
                    });
            });
        }



        function search() {
            layui.use('table', function() {
                let table = layui.table;
                table.reload('roleTb', {where: {departmentName: document.getElementById('departmentName').value}});
            })
        }

</script>
</body>
</html>
